﻿<%@ Page Title="" Language="C#" MasterPageFile="~/administrator/backend.Master" AutoEventWireup="true" CodeBehind="register-add.aspx.cs" Inherits="VQWEB.administrator.english.classroom.register_add" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Content_backend" runat="server">
    <form id="frmObjects" action="" method="post">
    </form>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Script_backend" runat="server">
   <script type="text/javascript">
       ShowToolBar("edit");
       var url_ashx = "/admin/english/classroom/handler";
       var url_input = '<%=ResolveUrl("~/administrator/templates/input.tpl") %>';

       $(document).ready(function () {
           $.get(url_ashx, { view_register: "view_register", Id: GetId() }, function (data) {
               var parse = $.parseJSON(data);
               var array_classroom;
               if (CheckAtionInPath("add")) {
                   array_classroom = array_select(parse.classroom);
                   loadform(0, "", "", "", "","", false, false, array_classroom);
               }
               else if (CheckAtionInPath("edit")) {
                   var classroom = parse.classroom;
                   var register = parse.register;
                   array_classroom = array_select(parse.classroom);
                   loadform(register.id, register.fullname, register.phone, register.email, register.content, register.date,register.status, register.active, array_classroom);

               }
           });
       });
       function loadform(id, fullname, phone, email, content, date,status, active,array_classroom) {
           $.jqoteload(url_input, function (tmpl) {
               $("#frmObjects").multiple("select", "classroom_id", array_classroom, "Classroom:", tmpl.input_tpl);
               $("#frmObjects").single("hidden", "register_id", id, null, null, tmpl.input_tpl);
               $("#frmObjects").single("text", "register_fullname", fullname, "Full Name:", null, tmpl.input_tpl);
               $("#frmObjects").single("text", "register_phone", phone, "Phone:", null, tmpl.input_tpl);
               $("#frmObjects").single("text", "register_email", email, "Email:", null, tmpl.input_tpl);
               $("#frmObjects").single("editor", "register_content", content, "Content:", null, tmpl.input_tpl);
               $("#frmObjects").single("text", "register_date", date, "Date:", null, tmpl.input_tpl);
               $("#frmObjects").single("checkbox", "register_status", true, "Home", active, tmpl.input_tpl);
               $("#frmObjects").single("checkbox", "register_active", true, "Active", active, tmpl.input_tpl);
               tinymce.init({ selector: 'textarea#tinymce' });
           });

       }

       $(document).on("click", "#btnCancel", function () {
           window.location = "/admin/english/classroom/register/list";
       });
       $(document).on("click", "#btnSave", function () {
           var value = tinymce.get('tinymce').getContent();
           $("textarea[name='register_content']").val(value);
           var arr = $("#frmObjects").serializeObject();
           $.post(url_ashx, { add_register: window.escape(arr) }, function (data) {
               alert(data);
               window.location = "/admin/english/classroom/register/list";
           });
       });
    </script>
</asp:Content>
